<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : advertisement.class.php   FILE_PATH : \classes\application\advertisement.class.php
 * ....广告管理
 * 广告种类：浮动广告、漂浮广告、flash广告、跑马灯广告、轮播广告
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Wed Sep 19 16:45:30 CST 2007
 */

defined('Base_Use_Sign') or die("this is invalid system!please contact <a href='http://www.shopnc.net'>www.shopnc.net</>.");

class AdvertisementClass extends FrameWork {
	/**
	 * 增加广告主题
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function addAdv($input_param){
		$arr = array();
		if (is_array($input_param)){
			foreach ($input_param as $k => $v){
				if (trim($v) != ''){
					$arr[$k] = $v;
				}
			}
		}
		return $GLOBALS['db']->InsertRow($arr,"adv_theme","adv_id");
	}
	
	/**
	 * 广告列表
	 * @author  
	 * @param  
	 * @return bool
	 */
	function listAdv($condition,&$obj_page){
		$conditionstr = $this->_conditionSearch($condition);
		$link_array = $GLOBALS['db']->GetList($conditionstr, $obj_page, "adv_theme");
		return $link_array;
	}
	
	/**
	 * 构造检索条件
	 * @author     
	 * @param  
	 * @return string
	 */
	function _conditionSearch($condition){
		$condition_str = "";
		
		//调用代码
		if ($condition['code'] != ''){
			$condition_str .= " and adv_code ='". $condition['code'] ."'";
		}
		//类别
		if ($condition['type'] != ''){
			$condition_str .= " and adv_type ='". $condition['type'] ."'";
		}
		//状态
		if ($condition['state'] != ''){
			$condition_str .= " and adv_state ='". $condition['state'] ."'";
		}
		//开始时间
		if ($condition['start_date'] != ''){
			$condition_str .= " and adv_start_date <= '". $condition['start_date'] ."'";
		}
		//结束时间
		if ($condition['end_date'] != ''){
			$condition_str .= " and adv_end_date >= '". $condition['end_date'] ."'";
		}
		if ($condition['group_by'] != ''){
			$condition_str .= " group by ". $condition['group_by'] ."";
		}
		if ($condition['order_by'] != ''){
			$condition_str .= " order by ". $condition['order_by'] ."";
		}
		if ($condition['order'] != ''){
			$condition_str .= $condition['order'];
		}
		
		return $condition_str;
	}
	
	/**
	 * 缺指定信息
	 * @author     
	 * @param  
	 * @return array
	 */
	function getOneAdv($id){
		if (intval($id) > 0) {
			return $GLOBALS['db']->GetOneRow($id,'adv_theme','adv_id');
		}else {
			return false;
		}
	}
	
	/**
	 * 更新
	 * @author     
	 * @param  
	 * @return bool
	 */
	function updateAdv($input_param){
		if (is_array($input_param)){
			$arr = array();
			foreach ($input_param as $k => $v){
				$arr[$k] = $v;
			}
		}
		$insert_rs = $GLOBALS['db']->UpdateRow($arr['adv_id'],$arr, 'adv_theme', 'adv_id');
		return $insert_rs;
	}
	
	/**
	 * 删除
	 * @author workflow Develop Team  
	 * @param  $id 信息ID
	 * @return bool
	 */
	function delAdv($id){
		if (intval($id) > 0) {
			return $GLOBALS['db']->DeleOneRow(intval($id),'adv_theme','adv_id');
		}
		return false;
	}
}
?>